<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	/**
	 功能名称:添加学期功能
	 @author:
	 **/
%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>添加学期</title>
  <link href="<%=path %>/css/index_css.css" rel="stylesheet" type="text/css" />
  <script src="<%=path%>/dwr/engine.js"></script>
  <script src="<%=path%>/dwr/util.js"></script>
  <script src="<%=path%>/dwr/interface/shiyueDwr.js"></script>
  <script language="javascript" src="<%=path %>/js/syAjax.js"></script>
  <script type="text/javascript">
  		String.prototype.len=function(){		
		    var len = 0;
		    for (var i = 0; i < this.length; i++) {      
		        if (this.charCodeAt(i) > 255 || this.charCodeAt(i)<0) len += 2; else len ++;      
		    }      
			return len;
		}
	    function getSchoolTermCallBack(schoolTerm) {
	      var schoolTermName=document.getElementById("schoolTermName");
		  var schoolTermValue=document.getElementById("schoolTermValue");
          if(!schoolTerm){
            alert("该学期值存在，请确保学期值唯一！");
            //document.getElementById("schoolTermValue").select(); 注释 2011-8-23 14:52:18
          }else {	//异步提交 闷男 2012-8-1314
          	 syAjax.request("post","saveSchoolTermyearAndSchoolTermAction.action","schoolTerm.name="+schoolTermName.value+"&schoolTerm.schoolTermValue="+schoolTermValue.value,{success:initSuccessResult,fail:onFail,type:'plain'});
          }
        } 
          
        function isSchoolTermValueExsit(){
        var value=document.getElementById("schoolTermValue").value;
        shiyueDwr.isSchoolTermValueExsit(value,getSchoolTermCallBack);
        }
        
      function doAdd(){
	  var schoolTermName=document.getElementById("schoolTermName");
	  var schoolTermValue=document.getElementById("schoolTermValue");
	  if(schoolTermName.value==""){
	    alert("学期不能为空！");
	    schoolTermName.focus();
	    return;
	  }
	  validateSchoolTerm(schoolTermValue);
	}
	
	function initSuccessResult(response){
	  window.returnValue=response;
	  window.close();
	}
	
     function validateSchoolTerm(obj){
			var re = /^\d*$/;
            if(obj.value.length!=0 && re.test(obj.value)){ 
            isSchoolTermValueExsit();         
           }else{
            alert("你输入的学期值格式不符合要求！");
            return ;
           }
}
		window.onload=function(){
			
			valueMap['1']="秋季学期(第一学期)";
			valueMap['2']="春季学期(第二学期)";
			valueMap['3']="夏季学期(第三学期)";
			valueMap['9']="其他";
			document.getElementById("schoolTermValue").onchange();
		}
		var valueMap={};
		
		function changeSchoolTermValue(obj){
			document.getElementById("schoolTermName").value=valueMap[obj.value];
		}
	</script>
  </head>
  <body bgcolor="#ECE9D8">
  <form action="" method="post">
    <table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="25" align="left" valign="bottom" bgcolor="#ECE9D8" class="f_8">&nbsp;&nbsp;&nbsp;&nbsp;注：<span class="f_11">*</span>为必填项</td>
  </tr>
  <tr>
    <td height="12" align="center" valign="middle" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="top" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="30" align="right" class="f_6"><span class="f_11">*</span> 学期值：</td>
        <td align="left"><!-- <input type="text" name="schoolTerm.schoolTermValue"  id="schoolTermValue"/> -->
        	<select name="schoolTerm.schoolTermValue" style="width:155px;" onchange="changeSchoolTermValue(this);" id="schoolTermValue">
        		<option value="1">1</option>
        		<option value="2">2</option>
        		<option value="3">3</option>
        		<option value="9">9</option>
        	</select>
        </td>
      </tr>
      <!-- <tr>
        <td height="20" align="right" class="f_6">&nbsp;</td>
        <td align="left" valign="top" class="f_2">注：学期值为正整数，且必须唯一。</td>
      </tr> -->
      <tr>
        <td width="25%" height="30" align="right" class="f_6"><span class="f_11">* </span>学期名称：</td>
        <td width="75%" align="left">
        <input type="text" name="schoolTerm.name" id="schoolTermName" maxlength="25"/>
        </td>
      </tr>      
     
      

    
    </table></td>
  </tr>
  <tr>
    <td height="25" align="center" valign="middle" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="55" align="center" valign="middle" bgcolor="#ECE9D8"><input type="button"" value="提 交" onclick="doAdd();" /></td>
  </tr>
</table>
</form>
  </body>
</html>
